#!/usr/bin/python
# encoding=utf-8
# version: 2017-12-21 17:38:21

import sys
import os
import shutil

enter_cwd_dir = ''
python_file_dir = ''


def parse_arg(argv):
    if len(argv) != 1:
        return False, None
    return True, argv


def get_exe_path(simple_path):
    global enter_cwd_dir
    global python_file_dir
    return os.path.join(enter_cwd_dir, python_file_dir, simple_path)


def usage():
    print 'this is usage()'

if __name__ == '__main__':
    success, args = parse_arg(sys.argv)
    if not success:
        usage()
        exit(-1)
    enter_cwd_dir = os.getcwd()
    python_file_dir = os.path.dirname(sys.argv[0])

    if os.path.exists(get_exe_path('./ResVer.txt')) is False:
        print 'can not find ResVer.txt'
        exit(0)

    flag_files = []
    with open(get_exe_path('./ResVer.txt'), 'r') as f:
        read_data = f.readlines()
        for read_line in read_data:
            if len(read_line.strip()) > 0:
                lines = read_line.strip().split(',', 1)
                if len(lines) == 2:
                    flag_files.append(lines[0].strip())
    if flag_files.count('Android') == 0:
        flag_files.append('Android')

    if os.path.isdir(get_exe_path('./FlagFiles/')):
        shutil.rmtree(get_exe_path('./FlagFiles/'))
    os.mkdir(get_exe_path('./FlagFiles/'))

    file_list = os.listdir(get_exe_path('./'))
    for file_name in file_list:
        if os.path.isdir(file_name):
            continue
        if file_name.endswith('.py') or file_name.endswith('.pyc') or file_name.endswith('.log'):
            continue
        if flag_files.count(file_name) == 1:
            shutil.copy(os.path.join(get_exe_path('./'), file_name),
                        os.path.join(get_exe_path('./FlagFiles/'), file_name))
